class Categor < ActiveRecord::Base
  has_many :products
  belongs_to :shop, :autosave => true
  has_attached_file :photo, :url => "/:attachment/:class/:style_:id.:extension",
    :path => ":rails_root/public/:attachment/:class/:style_:id.:extension", :default_url => "/images/default/categor.jpg"
  validates_attachment_presence :photo, :message  => I18n.t("errors.messages.attachment.presence")
  validates_attachment_size :photo, :less_than => 50.kilobytes, :message => I18n.t("errors.messages.attachment.size")
  validates_attachment_content_type :photo, :content_type => ['image/jpeg'], :message => I18n.t("errors.messages.attachment.content_type")
  validates :name, :length => {:within => 3..40}
  validates_inclusion_of :status, :in => %w[banned approved]
  def add_order_product order_product
    @order_products = [] if @order_products.nil?
    @order_products << order_product
  end

  def get_order_products
    @order_products
  end
end
